home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_qt.idb / usr / freeware / include / Qt / qcache.h.z / qcache.h
Encoding:
C/C++ Source or Header  |  1998-10-28  |  7.8 KB  |  185 lines

  1. /****************************************************************************
  2. ** $Id: qcache.h,v 2.3 1998/07/03 00:09:43 hanord Exp $
  3. **
  4. ** Definition of QCache template/macro class
  5. **
  6. ** Created : 950209
  7. **
  8. ** Copyright (C) 1992-1998 Troll Tech AS.  All rights reserved.
  9. **
  10. ** This file is part of Qt Free Edition, version 1.40.
  11. **
  12. ** See the file LICENSE included in the distribution for the usage
  13. ** and distribution terms, or http://www.troll.no/free-license.html.
  14. **
  15. ** IMPORTANT NOTE: You may NOT copy this file or any part of it into
  16. ** your own programs or libraries.
  17. **
  18. ** Please see http://www.troll.no/pricing.html for information about 
  19. ** Qt Professional Edition, which is this same library but with a
  20. ** license which allows creation of commercial/proprietary software.
  21. **
  22. *****************************************************************************/
  23.  
  24. #ifndef QCACHE_H
  25. #define QCACHE_H
  26.  
  27. #ifndef QT_H
  28. #include "qgcache.h"
  29. #endif // QT_H
  30.  
  31.  
  32. #if defined(USE_MACROCLASS)
  33.  
  34. #include "qgeneric.h"
  35.  
  36. #if !defined(name2)
  37. #define name2(a,b)    name2_xx(a,b)
  38. #define name2_xx(a,b) a##b
  39. #endif
  40.  
  41. #if defined(DEFAULT_MACROCLASS)
  42. #define QCachedeclare QCacheMdeclare
  43. #define QCache QCacheM
  44. #endif
  45. #define QCacheM(type) name2(QCacheM_,type)
  46.  
  47. #define QCacheMdeclare(type)                              \
  48. class QCacheM(type) : public QGCache                          \
  49. {                                          \
  50. public:                                          \
  51.     QCacheM(type)( const QCacheM(type) &c ) : QGCache(c) {}              \
  52.     QCacheM(type)( int maxCost=100, int size=17, bool cs=TRUE,bool ck=TRUE )  \
  53.     : QGCache( maxCost, size, cs, ck, FALSE ) {}                  \
  54.    ~QCacheM(type)()              { clear(); }                  \
  55.     QCacheM(type) &operator=( const QCacheM(type) &c )                  \
  56.             { return (QCacheM(type)&)QGCache::operator=(c); }     \
  57.     int      maxCost()   const          { return QGCache::maxCost(); }          \
  58.     int      totalCost() const          { return QGCache::totalCost(); }          \
  59.     void  setMaxCost( int m )          { QGCache::setMaxCost(m); }          \
  60.     uint  count()     const          { return QGCache::count(); }          \
  61.     uint  size()      const          { return QGCache::size(); }          \
  62.     bool  isEmpty() const          { return QGCache::count() == 0; }          \
  63.     bool  insert( const char *k, const type *d, int c=1, int p=0 )          \
  64.                       { return QGCache::insert(k,(GCI)d,c,p);}\
  65.     bool  remove( const char *k )     { return QGCache::remove(k); }          \
  66.     type *take( const char *k )          { return (type *)QGCache::take(k); }    \
  67.     void  clear()              { QGCache::clear(); }              \
  68.     type *find( const char *k, bool ref=TRUE ) const                  \
  69.                        { return (type *)QGCache::find(k,ref);}\
  70.     type *operator[]( const char *k ) const                      \
  71.                       { return (type *)QGCache::find(k); }    \
  72.     void  statistics() const          { QGCache::statistics(); }          \
  73. private:                                      \
  74.     void  deleteItem( GCI d )          { if ( del_item ) delete (type *)d; }   \
  75. }
  76.  
  77.  
  78. #if defined(DEFAULT_MACROCLASS)
  79. #define QCacheIteratordeclare QCacheIteratorMdeclare
  80. #define QCacheIterator QCacheIteratorM
  81. #endif
  82. #define QCacheIteratorM(type) name2(QCacheIteratorM_,type)
  83.  
  84. #define QCacheIteratorMdeclare(type)                          \
  85. class QCacheIteratorM(type) : public QGCacheIterator                  \
  86. {                                          \
  87. public:                                          \
  88.     QCacheIteratorM(type)( const QCacheM(type) &c )                  \
  89.                   : QGCacheIterator( (QGCache &)c ) {}          \
  90.     QCacheIteratorM(type)( const QCacheIteratorM(type) &ci )              \
  91.                   : QGCacheIterator( (QGCacheIterator &)ci ) {}   \
  92.     QCacheIteratorM(type) &operator=(const QCacheIteratorM(type)&ci)          \
  93.     { return (QCacheIteratorM(type)&)QGCacheIterator::operator=( ci ); }  \
  94.     uint  count()   const    { return QGCacheIterator::count(); }          \
  95.     bool  isEmpty() const    { return QGCacheIterator::count() == 0; }          \
  96.     bool  atFirst() const    { return QGCacheIterator::atFirst(); }          \
  97.     bool  atLast()  const    { return QGCacheIterator::atLast(); }          \
  98.     type *toFirst()         { return (type *)QGCacheIterator::toFirst(); }   \
  99.     type *toLast()         { return (type *)QGCacheIterator::toLast(); }    \
  100.     operator type *() const  { return (type *)QGCacheIterator::get(); }          \
  101.     type *current()   const  { return (type *)QGCacheIterator::get(); }          \
  102.     const char *currentKey() const                          \
  103.                  { return QGCacheIterator::getKey();}          \
  104.     type *operator()()         { return (type *)QGCacheIterator::operator()();} \
  105.     type *operator++()         { return (type *)QGCacheIterator::operator++();} \
  106.     type *operator+=(uint j) { return (type *)QGCacheIterator::operator+=(j);}\
  107.     type *operator--()         { return (type *)QGCacheIterator::operator--();} \
  108.     type *operator-=(uint j) { return (type *)QGCacheIterator::operator-=(j);}\
  109. }
  110.  
  111. #endif // USE_MACROCLASS
  112.  
  113.  
  114. #if defined(USE_TEMPLATECLASS)
  115.  
  116. #if defined(DEFAULT_TEMPLATECLASS)
  117. #undef    QCache
  118. #define QCache QCacheT
  119. #endif
  120.  
  121. template<class type> class QCacheT : public QGCache
  122. {
  123. public:
  124.     QCacheT( const QCacheT<type> &c ) : QGCache(c) {}
  125.     QCacheT( int maxCost=100, int size=17, bool cs=TRUE, bool ck=TRUE )
  126.     : QGCache( maxCost, size, cs, ck, FALSE ) {}
  127.    ~QCacheT()                  { clear(); }
  128.     QCacheT<type> &operator=( const QCacheT<type> &c )
  129.             { return (QCacheT<type>&)QGCache::operator=(c); }
  130.     int      maxCost()   const          { return QGCache::maxCost(); }
  131.     int      totalCost() const          { return QGCache::totalCost(); }
  132.     void  setMaxCost( int m )          { QGCache::setMaxCost(m); }
  133.     uint  count()     const          { return QGCache::count(); }
  134.     uint  size()      const          { return QGCache::size(); }
  135.     bool  isEmpty()   const          { return QGCache::count() == 0; }
  136.     bool  insert( const char *k, const type *d, int c=1, int p=0 )
  137.                       { return QGCache::insert(k,(GCI)d,c,p);}
  138.     bool  remove( const char *k )     { return QGCache::remove(k); }
  139.     type *take( const char *k )          { return (type *)QGCache::take(k); }
  140.     void  clear()              { QGCache::clear(); }
  141.     type *find( const char *k, bool ref=TRUE ) const
  142.                        { return (type *)QGCache::find(k,ref);}
  143.     type *operator[]( const char *k ) const
  144.                       { return (type *)QGCache::find(k);}
  145.     void  statistics() const          { QGCache::statistics(); }
  146. private:
  147.     void  deleteItem( GCI d )          { if ( del_item ) delete (type *)d; }
  148. };
  149.  
  150.  
  151. #if defined(DEFAULT_TEMPLATECLASS)
  152. #undef    QCacheIterator
  153. #define QCacheIterator QCacheIteratorT
  154. #endif
  155.  
  156. template<class type> class QCacheIteratorT : public QGCacheIterator
  157. {
  158. public:
  159.     QCacheIteratorT( const QCacheT<type> &c ):QGCacheIterator((QGCache &)c) {}
  160.     QCacheIteratorT( const QCacheIteratorT<type> &ci)
  161.                 : QGCacheIterator( (QGCacheIterator &)ci ) {}
  162.     QCacheIteratorT<type> &operator=(const QCacheIteratorT<type>&ci)
  163.     { return ( QCacheIteratorT<type>&)QGCacheIterator::operator=( ci ); }
  164.     uint  count()   const     { return QGCacheIterator::count(); }
  165.     bool  isEmpty() const     { return QGCacheIterator::count() == 0; }
  166.     bool  atFirst() const     { return QGCacheIterator::atFirst(); }
  167.     bool  atLast()  const     { return QGCacheIterator::atLast(); }
  168.     type *toFirst()          { return (type *)QGCacheIterator::toFirst(); }
  169.     type *toLast()          { return (type *)QGCacheIterator::toLast(); }
  170.     operator type *() const   { return (type *)QGCacheIterator::get(); }
  171.     type *current()   const   { return (type *)QGCacheIterator::get(); }
  172.     const char *currentKey() const
  173.                   { return QGCacheIterator::getKey();}
  174.     type *operator()()          { return (type *)QGCacheIterator::operator()();}
  175.     type *operator++()          { return (type *)QGCacheIterator::operator++(); }
  176.     type *operator+=(uint j)  { return (type *)QGCacheIterator::operator+=(j);}
  177.     type *operator--()          { return (type *)QGCacheIterator::operator--(); }
  178.     type *operator-=(uint j)  { return (type *)QGCacheIterator::operator-=(j);}
  179. };
  180.  
  181. #endif // USE_TEMPLATECLASS
  182.  
  183.  
  184. #endif // QCACHE_H
  185.